﻿using HslCommunication;
using NetCore8Demo.Models.PLC;

namespace NetCore8Demo.ViewModels.PLC;

/// <summary>
/// ReadAll方法传的是PlcAddressInfo集合 WritePlc 方法传的是PlcAddressInfo对象
/// 其余方法传的对应的地址（string）,不同的类型的值
/// 字符串的读写，定义了俩参数，长度、编码类型，单调用读写字符串方法时，这俩参数可不传。
/// 三菱单独调用方法时，长度也必须传
/// 实现字符串读写的方法时，要处理长度。字符编码不传（即是默认值的情况）
/// </summary>
public interface IPlcReadAndWriteInterface
{
    OperateResult ConnPlc(string ip, int port);

    OperateResult ClosePlc();


    #region 读取PLC

    OperateResult ReadAll(List<PlcAddressInfo> plcAddressInfoList);
    OperateResult<bool> ReadBool(string address);

    OperateResult<byte> ReadByte(string address);

    OperateResult<short> ReadShort(string address);

    OperateResult<ushort> ReaduShort(string address);

    OperateResult<int> ReadInt(string address);

    OperateResult<uint> ReaduInt(string address);

    OperateResult<long> ReadLong(string address);

    OperateResult<ulong> ReaduLong(string address);


    OperateResult<float> ReadFloat(string address);

    OperateResult<double> ReadDouble(string address);

    /// <summary>
    /// 读取字符串的方法，支持不传长度跟编码格式读写
    /// 重写的这个方法，里面要有 EncodingType不同时的处理，length为0时的处理
    /// 默认的ReadAll()方法里,传的是PlcAddressInfo对象，对象的默认值是0，相当于是调用的这个方法的全参数模式，而不是没传参数
    /// </summary>
    /// <param name="address"></param>
    /// <param name="length"></param>
    /// <param name="encodingType"></param>
    /// <returns></returns>
    OperateResult<string> ReadString(string address, ushort length=0, EncodingType encodingType = EncodingType.None);

    #endregion

    #region 写入PLC

    OperateResult WritePlc(PlcAddressInfo plcAddressInfo, string value);
    OperateResult WriteBool(string address, bool value);

    OperateResult WriteByte(string address, byte value);

    OperateResult WriteShort(string address, short value);

    OperateResult WriteuShort(string address, ushort value);

    OperateResult WriteInt(string address, int value);

    OperateResult WriteuInt(string address, uint value);

    OperateResult WriteLong(string address, long value);

    OperateResult WriteuLong(string address, ulong value);

    OperateResult WriteFloat(string address, float value);

    OperateResult WriteDouble(string address, double value);

    /// <summary>
    /// 写入字符串的方法，支持不传长度跟编码格式读写
    /// 重写的这个方法，里面要有 EncodingType不同时的处理，length为0时的处理，三菱的HSL没有不传长度的写法，所以三菱的没有Length为0时的处理
    /// 默认的WritePlc()方法里,传的是PlcAddressInfo对象，对象的默认值是0，相当于是调用的这个方法的全参数模式，而不是没传参数
    /// </summary>
    /// <param name="address"></param>
    ///  <param name="value"></param>
    /// <param name="length"></param>
    /// <param name="encodingType"></param>
    /// <returns></returns>
    OperateResult WriteString(string address, string value,int length=0, EncodingType encodingType = EncodingType.None);

    #endregion
}

public class PlcReadAndWriteDemo : IPlcReadAndWriteInterface
{

    public bool InitFlag;
    // virtual 虚方法,可重写
    public virtual OperateResult ClosePlc()
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult ReadAll(List<PlcAddressInfo> plcAddressInfoList)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult ConnPlc(string ip, int port)
    {
        throw new NotImplementedException();
    }

    

    public virtual OperateResult<bool> ReadBool(string address)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult<byte> ReadByte(string address)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult<double> ReadDouble(string address)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult<string> ReadString(string address, ushort length = 0, EncodingType encodingType = EncodingType.None)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult<float> ReadFloat(string address)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult<int> ReadInt(string address)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult<long> ReadLong(string address)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult<short> ReadShort(string address)
    {
        throw new NotImplementedException();
    }


    public virtual OperateResult<uint> ReaduInt(string address)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult<ulong> ReaduLong(string address)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult<ushort> ReaduShort(string address)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult WritePlc(PlcAddressInfo plcAddressInfo, string value)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult WriteBool(string address, bool value)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult WriteByte(string address, byte value)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult WriteDouble(string address, double value)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult WriteFloat(string address, float value)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult WriteInt(string address, int value)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult WriteLong(string address, long value)
    {
        throw new NotImplementedException();
    }


    public virtual OperateResult WriteShort(string address, short value)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult WriteString(string address, string value, int length = 0, EncodingType encodingType = EncodingType.None)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult WriteuInt(string address, uint value)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult WriteuLong(string address, ulong value)
    {
        throw new NotImplementedException();
    }

    public virtual OperateResult WriteuShort(string address, ushort value)
    {
        throw new NotImplementedException();
    }
}